/**
 * 
 */
package server.room;


/**
 * Defines room states
 * 
 * @author Kamil Nowak
 * 
 */
public enum RoomState {
	
	/**
	 * Room is ready to be joined
	 */
	FREE,
	/**
	 * Room is occupied. Cannot join room.
	 */
	OCCUPIED,
	/**
	 * Room is in game 
	 */
	GAME,
	/**
	 * One of the players sent finish request
	 */
	PENDING_FINISH, 
	/**
	 * One of the players sent move request
	 */
	MOVE,
	/**
	 * One of the players sent chessman promotion request
	 */
	PROMO;

	/**
	 * Checks wheather exists transition from old state to new stete
	 * 
	 * @param oldState
	 * @param newState
	 * @return
	 */
	public static boolean existsTransision(RoomState oldState, RoomState newState) {
	
		if (oldState == FREE && 
				(newState == OCCUPIED)) {
			return true;
		} else if (oldState == FREE && 
				(newState == FREE)) {
			return true;
		} else if (oldState == OCCUPIED && 
				(newState == FREE)) {
			return true;
		} else if (oldState == OCCUPIED && 
				(newState == GAME)) {
			return true;
		} else if (oldState == MOVE && 
				(newState == PENDING_FINISH)) {
			return true;
		} else if (oldState == MOVE && 
				(newState == FREE)) {
			return true;
		} else if (oldState == GAME && 
				(newState == MOVE)) {
			return true;
		} else if (oldState == GAME && 
				(newState == FREE)) {
			return true;
		} else if (oldState == MOVE && 
				(newState == GAME)) {
			return true;
		} else if (oldState == GAME && 
				(newState == PROMO)) {
			return true;
		} else if (oldState == PROMO && 
				(newState == GAME)) {
			return true;
		} else if (oldState == PROMO && 
				(newState == OCCUPIED)) {
			return true;
		} else if (oldState == PENDING_FINISH && 
				(newState == OCCUPIED)) {
			return true;
		} else if (oldState == PENDING_FINISH && 
				(newState == GAME)) {
			return true;
		}  else if (oldState == PENDING_FINISH && 
				(newState == FREE)) {
			return true;
		}
		
		return false;
	}
	
}
